package com.wushijia.highconcurrency.threadlocal;

public class ThreadLocalDemo01 {

  public static void main(String[] args) {

    ThreadLocal local = new ThreadLocal<>();

    //在主线程中更改变量
    local.set("我是main");
    System.out.println("main:" + local.get());

    //在A线程中程中更改变量
    new Thread("ThreadA") {
      @Override
      public void run() {
        super.run();
        local.set("我是ThreadA");
        System.out.println("ThreadA:" + local.get());
      }
    }.start();

    //在B线程中程中未对变量进行操作，也没有初始化
    new Thread("ThreadB") {
      @Override
      public void run() {
        super.run();
        System.out.println("ThreadB:" + local.get());
      }
    }.start();


  }
}
